import Data.List
--nthPermutation all@(x:xs) nth tries
--        | nOfPerms < nth = nthPermutation xs (nth - nOfPerms)
--        | otherwise = nthPermutation' all
--          where nOfPerms = numberOfPerms xs
--nthPermutation' xs = xs

perms :: Eq a => [a] -> [[a]]
perms [] = [[]]
perms xs = [ x:ps | x <- xs , ps <- perms (xs\\[x]) ]


facs = scanl (*) 1 [1..]
fac n = facs !! n
numberOfPerms = fac . length

main = perms "0123456789" !! 999999